<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 必须的 meta 标签 -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap 的 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../../static/css/main.css" th:href="@{/static/css/main.css}">
    <title>订单查询</title>
</head>
<body>
<nav class="nav nav-pills nav-justified">
    <a class="nav-link" th:href="@{/book/randBook}">首页</a>
    <a class="nav-link" th:href="@{/book/bookBrother}">分类与购买</a>
    <a class="nav-link " th:href="@{/admin/userCenter}">个人中心</a>
    <a class="nav-link active" th:href="@{/shop/selectAllShop}">购物车</a>
    <a class="nav-link" th:href="@{/order/selectOrderLastAll}">查询订单</a>
</nav>
<br>
<br>
<button th:onclick="goShop()" type="button" class="upd btn btn-primary" style="margin-left: 1450px">去支付</button>

<div class="row-10">
    <div id="tab" th:fragment="tab">
        <table class="table">
            <thead>
            <tr>
                <th scope="col">状态</th>
                <th scope="col">书名</th>
                <th scope="col">单价</th>
                <th scope="col">评分</th>
                <th scope="col">数量</th>
                <th scope="col">操作</th>
            </tr>
            </thead>
            <tbody id="tbody">
            <tr th:each="book:${books}">
                <th  scope="row"><label>
                    <input id="bookId"  type="checkbox" th:value="${book.id}">
                </label></th>
                <td th:text="${book.bookName}">《平凡世界》</td>
                <td th:text="${book.price}">123</td>
                <td th:text="${book.mark}">7.7</td>
                <td th:text="${book.count}">2本</td>
                <td>
                    <button th:onclick="|motai(${book.id})|" type="button" class="upd btn btn-dark">修改</button>
                    <a th:href="@{/shop/delete/{bookId}(bookId=${book.id})}"><button type="button"  class="upd btn btn-danger">删除</button></a>
                    <!--模态窗口-->
                    <div id="myMo" class="modal" tabindex="-1">
                        <div class="container">
                            <div class="modal-content">
                                <div class="modal-body">
                                    购买数量：<input type="text" id="count" name="count"><br>
                                    <button onclick="rush()" type="submit">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>













<!-- JavaScript 文件是可选的。从以下两种建议中选择一个即可！ -->
<!-- 选项 1：jQuery 和 Bootstrap 集成包（集成了 Popper） -->

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

<script>


    let bookId;

    function motai(i) {
        bookId = i
        $('#myMo').modal('show');
    }

    function rush() {
        var count = $("#count").val();
        $.ajax({
            url:'/bookCity/shop/updateCount',
            data:{
                bookId:bookId,
                count:count,
            }
        })
        $("#myMo").modal('hide');
        alert("修改成功！");
        window.location.href="selectAllShop"
    }


    function goShop() {
        var bookIds = $("#tbody input[type='checkbox']:checked");
        var books="";

        $.each(bookIds,function () {
            books += "bookId=" + this.value + "&"
        });

        books.substr(0,books.length-1);


        if(books.length === 0) {
            alert("请选择要支付的商品");
            return ;
        }
        console.log(books)

        $.ajax({
            url:'/bookCity/shop/goShop',
            data:{
                books:books
            },
        })
        alert("欢迎来到支付页面");
        window.location.href="goShop";
    }
</script>
</body>
</html>